The present invention relates to a method for locating codes in bidimensional images.
Codes are known for coding information, for example for optical identification of objects. In particular, at present, extensive use is made of bar codes, used in an ever-increasing variety of applications, owing to their compactness, robustness with respect to environmental conditions, which permit automatic decoding even in presence of a high noise level and the possibility of automatic reading and interpretation. However, they allow storage of a relatively limited amount of information; in order to overcome this limitation, bidimensional codes have recently been proposed, such as the Datamatrix, Maxicode, QR-Code and stacked codes (for example PDF417), examples of which are shown respectively in FIGS. 1a, 1b, 1c and 1d. 
These bidimensional codes can also be read by acquiring bidimensional images in an area where a code is expected and locating the code within the-image, for later decoding. In particular, code locating must permit discriminating, within the image stored in a processor memory, the region or regions comprising one or a plurality of codes, from areas comprising other objects or figures. In first instance, locating is aimed at finding specific recognition patterns, typical for each code; knowledge of a pattern location and of the type of code makes it possible to extract the code from the image and then to decode it.
The object of the invention is to provide a new method for locating codes in bidimensional images.
According to the present invention, a method is provided for locating codes in bidimensional images, comprising the step of acquiring a bidimensional image formed by a plurality of dots characterized by a brightness value, characterized by the steps of:
dividing said bidimensional image into a plurality of image regions, each of said image regions comprising a respective first number of dots;
for each of said image regions, determining a first quantity correlated to the brightness variation intensity of respective dots with respect to adjacent dots;
for each of said image regions, determining at least one second quantity correlated to the brightness variation direction of the respective dots with respect to adjacent dots; and
determining any presence and type of a code in each of said image regions, on the basis of said first and said second quantities.
The image is preferably divided into blocks of a sufficient dimension to contain a portion of a code, or at the most an entire code, but no more than one code, to simplify subsequent processing; in each block, the brightness variation intensity is evaluated, to eliminate blocks with low contrast, which definitely do not contain codes; and for each sufficiently contrasted block, the brightness variation direction is evaluated, which is correlated to the type of any present code.
To estimate the brightness variation intensity, the dot gradient is preferably used and the values of intensity of the gradient, calculated for all dots of each block are summed; then only blocks are considered which have a sum greater than a predetermined threshold. In addition, to estimate the brightness variation direction, the dot brightness gradient direction is used and for the considered blocks, the prevalent gradient direction or directions is or are calculated. For each considered block, if there is a single prevalent direction, it is decided that the block contains a linear (bar or stacked) code; if there are two prevalent directions, this means that a Datamatrix code or a QR-Code is involved.
The locating information (block containing a code) and the code type are then used to carry out fine localization and segmentation, to determine accurately code outlines.